<?php
/**
 * @software         [JiJinCMS]
 * @author           [上海集锦信息科技有限公司]
 * @website          [http://www.jijinweb.com]
 * @email            [sunny@jijinweb.com]
 **/
namespace app\admin\controller;
use think\facade\View;
use app\admin\model\RoleModel;
use think\facade\Db;
use think\facade\Request;
class Example extends \app\admin\controller\Admin{
    public function __construct(\think\App $app) {
        parent::__construct($app);
        View::assign("cat",["分类1","分类2","分类3"]);
        $listRows=Request::param("listRow")?Request::param("listRow"):config("app.page_show_line");//每页显示多少条
        $data=Db::name("user_log")->order("addtime desc")->paginate(['list_rows'=>$listRows,'query' => request()->param()]);
        $pagelist = $data->render();
        View::assign("pagelist",$pagelist);
        View::assign("data",$data);
        //
        $typeInc=["列表","增加","弹窗","上传"];
        View::assign("typeInc",$typeInc);

        View::assign("pagetitle","列表信息");

    }
    public function index(){
        $where=[];
        if(Request::param("type")){
            $where['type']=Request::param("type");
        }
        $example_data=Db::name("example")->where($where)->order("id asc")->select()->toArray();
        foreach($example_data as $k=>$v){
            $example_data[$k]["fun"]=explode(" ",$v['fun']);
        }
        View::assign("example_data",$example_data);
        $temp=Request::param("temp");
        if(!$temp){
            $temp="index";
        }
        return View::fetch($temp);
    }
    //
    public function add(){
        if(request()->isPost()){
            $data=Request::param();
            Db::name('example')->save($data);
            //
            $this->success("添加成功");
        }else{
            return View::fetch();
        }
    }
    public function update(){
        if(request()->isPost()){
            $data=Request::param();
            Db::name('example')->update($data);
            $this->success("修改成功");

        }else{
            $id=Request::param("id",0,"intval");
            $r=Db::name('example')->find($id);
            View::assign("r",$r);
            return View::fetch();
        }
    }
    //
    public function delete(){
        $id=Request::param("id");
        Db::name('example')->delete($id);
        $this->success("删除成功");
    }
}
